package com.hyst.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.hyst.common.ResultBean;
import com.hyst.common.ResultPage;
import com.hyst.domain.LessonLevel;
import com.hyst.service.LessonLevelService;

/**
 * @Description:课程级别controller
 * @author：dy 
 *@Date：2018年08月26日
 */
@RestController
@RequestMapping("lessonLevels")
@CrossOrigin(maxAge = 3600, origins = "*")
public class LessonLevelController {
	@Autowired
	private LessonLevelService lessonLevelService;
	
	@GetMapping
	public ResultPage<LessonLevel> getProjects(LessonLevel lessonLevel) {
		return ResultPage.success(lessonLevelService.list(lessonLevel));
	}


	@PostMapping
	public ResultBean<LessonLevel> creat(final LessonLevel lessonLevel) {
		return ResultBean.success(lessonLevelService.insert(lessonLevel));
	}

	/**
	 * @Description: 根据主键查询
	 * @param id
	 * @return ResultBean<LessonLevel>
	 */
	@GetMapping("{id}")
	public ResultBean<LessonLevel> getByPriKey(@PathVariable("id") final Integer id) {
		return ResultBean.success(lessonLevelService.getByPriKey(id));
	}

	/**
	 * @Description: 根据主键更新全字段
	 * @param lessonLevel
	 * @return ResultBean<LessonLevel>
	 */
	@PatchMapping("{id}")
	public ResultBean<LessonLevel> update(final LessonLevel lessonLevel) {
		return ResultBean.success(lessonLevelService.update(lessonLevel));
	}

	/**
	 * @Description: 根据主键更新不为默认值的字段
	 * @param lessonLevel
	 * @return ResultBean<LessonLevel>
	 */
	//@PutMapping("{id}")
	@PostMapping("{id}")
	public ResultBean<LessonLevel> updatePatch(@PathVariable("id") final Integer id,
			final LessonLevel lessonLevel) {
		return ResultBean.success(lessonLevelService.updateSelective(lessonLevel));
	}

	/**
	 * @Description: 根据主键删除
	 * @param id
	 * @return ResultBean<LessonLevel>
	 */
	@DeleteMapping("{id}")
	public ResultBean<LessonLevel> delete(@PathVariable("id") final Integer id) {
		return ResultBean.success(lessonLevelService.delete(id));
	}


}
